package visualcbir.cluster;

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import visualcbir.util.VSUtils;
import visualcbir.IBackStructureView;
import visualcbir.exception.NullBackStructureException;

/**
 *
 * @author sheila
 */
public class VSEdgesBackStructure implements IBackStructureView {
    private ArrayList <VSEdge> aoEdges;

    public void addEdge(VSEdge pEdge){
        aoEdges.add(pEdge);
    }

    @Override
    public void drawBackStructure(Graphics g) throws NullBackStructureException{
        if( aoEdges == null ){
            throw new NullBackStructureException();
        }
        Graphics2D g2d=((Graphics2D)g);
                
        for (int i = 0; i<this.aoEdges.size(); i++) {
            VSEdge oCurrentEdge = this.aoEdges.get(i);
            g2d.setColor(oCurrentEdge.getColor());
            g2d.setStroke(new BasicStroke(oCurrentEdge.getWidthline(), BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f));
            g2d.drawLine(oCurrentEdge.getoNodeFrom().getCenterPoint().x, oCurrentEdge.getoNodeFrom().getCenterPoint().y, oCurrentEdge.getoNodeTo().getCenterPoint().x, oCurrentEdge.getoNodeTo().getCenterPoint().y);
        }        
        VSUtils.resetGraphics(g);
    }

    @Override
    public void setObject(Object oObject) {
        this.aoEdges=(ArrayList<VSEdge>)oObject;
    }
}
